import requests
from lxml import etree

headers = {"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"}

url_start = 'https://tieba.baidu.com/f?kw=手办'
url_ends = []
response = requests.get(url_start,headers).text
html = etree.HTML(response)
"""
<div class="threadlist_title pull_left j_th_tit ">
    <a rel="noreferrer" href="/p/5829871721" title="为了血小板！买买买！" target="_blank" class="j_th_tit ">为了血小板！买买买！</a>
</div>
"""
url_starts = html.xpath('//div[@class="threadlist_title pull_left j_th_tit "]/a/@href')

for i in url_starts:
    if i == "/p/1635177441":
        continue
    url_end = 'https://tieba.baidu.com' + i
    response_tmp = requests.get(url_end,headers).text
    html_tmp = etree.HTML(response_tmp)
    photo = html_tmp.xpath('//img[@class="BDE_Image"]/@src')
    title = html_tmp.xpath('//h3[@class="core_title_txt pull-left text-overflow  "]/text()')
    data = {
        "title":title,
        "phto":photo
    }
    print(data)
